import { Body, Controller, Get, Post, Res, Query, HttpException, HttpStatus } from '@nestjs/common';
import { Response } from 'express';
import { RejectReasonService } from './rejectReason.service';
import { apibefore } from 'src/router';

@Controller(apibefore('/reject_reason_manager'))
export class RejectReasonControllerManager {
  constructor(private readonly service: RejectReasonService) {}

  @Get('/findAll_ByType')
  async findAll_ByType(@Query() params){
    let result = await this.service.findAll_ByType(params.type)
    return result.map(e => {
      return {
        id: e.id,
        name: e.reason
      }
    })
  }

  @Post('/save')
  save(@Body() data){
    return this.service.save(data.id, data.type, data.reason)
  }
  @Post('/save_batch')
  async save_batch(@Body() data){
    let err = await this.service.save_batch(data.list)
    if(err){
      return new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR)
    }else{
      return true
    }
  }
}
